#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <thread>
#include <mutex>
#include <QMainWindow>
#include "mechversionclient.h"
#include "elite_robot_sdk.h"
#include "rmgripper.h"

enum TaskEnum{
    TASK_NONE =-1,
    VERSION_GET_DRAWING_GUN_POINT = 1001,               //获取拔枪视觉点
    ROBOT_GET_JOINT_POS,                                //获取机械臂关节角
    ROBOT_MOV_JOINT_POS,                                //机械臂关节角运动
    ROBOT_GET_TCP_POSE,                                 //获取机械臂工具位姿
    ROBOT_MOV_LINE_TCP_POSE,                            //机械臂工具位姿直线运动
    GRIPPER_RETURN_ORIGIN,                              //夹爪回原点
    GRIPPER_NUM0_PUSH_MOVE,                             //夹爪预置点0推压运动
    GRIPPER_NUM0_SET_PARAMS,                            //夹爪预置点0参数设置
    GRIPPER_STOP_MOVE,                                  //夹爪停止运动
};

class PoseInfo
{
public:
    Param6D pose;
    double speed;
    double acc;
    double dec;
};

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private slots:
    void closeEvent(QCloseEvent * event);

    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_5_clicked();

    void on_pushButton_6_clicked();

    void on_pushButton_7_clicked();

    void on_pushButton_13_clicked();

    void on_pushButton_11_clicked();

    void on_pushButton_12_clicked();

    void on_pushButton_14_clicked();

    void on_pushButton_10_clicked();

private:
    Ui::MainWindow *ui;

    MechVersionClient   mm_client;
    EliteRobotSdk  elite_robot;
    RmGripper  rm_gripper;

    /*工作线程*/
    int mWorkerCurTask=TASK_NONE;
    bool mWorkerRunnig = false;
    std::condition_variable mWorkercond;
    bool mWorkerRecvStatus =false;
    std::mutex mWorkerProcMutex;
    std::thread worker;
    void workThreadFun();
    void print_mech_version_pose(MECH_VERSION_POSE mech_pose);

    MECH_VERSION_POSE joint_pos;
    MECH_VERSION_POSE tcp_pose;

    int deal_input_pose_str(std::string input_str, PoseInfo& pose_info);
};

#endif // MAINWINDOW_H
